﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using API.Models;
using PPG.DataAccess;
using PPG.CryptoProvider;
using System.Xml;
using System.Data;
using System.Configuration;
using System.Web;

namespace API.Controllers
{
    public class DefaultListsController : ApiController
    {
        DataSourceCommunicator dsComm = new DataSourceCommunicator(DataSourceCommunicator.ParamType.ServerCredentials, ConfigurationManager.AppSettings["DBServerName"].ToString(), ConfigurationManager.AppSettings["DBUserName"].ToString(), ConfigurationManager.AppSettings["DBPassword"].ToString());

        public HttpResponseMessage OptionsPatientDemographics()
        {
            var response = new HttpResponseMessage();
            response.StatusCode = HttpStatusCode.OK;
            return response;
        }

        public DefaultListResponse GetDefaultLists(int id)
        {
            DefaultListResponse response = new DefaultListResponse();

            dsComm.AddParameter("@ParamLoginID", id);
            string data = dsComm.ExecuteStoredProcedure("dbo.spGetDefaultLists");
            XmlTextReader xReader = new XmlTextReader(data, XmlNodeType.Document, null);
            DataSet ListsDataSet = new DataSet();
            ListsDataSet.ReadXml(xReader);

            if (ListsDataSet.Tables.Count > 0)
            {
                if(ListsDataSet.Tables[0] != null)
                {
                    response.Practices = ListsDataSet.Tables[0];
                }
                if (ListsDataSet.Tables[1] != null)
                {
                    response.Physicians = ListsDataSet.Tables[1];
                }
                //if (ListsDataSet.Tables[2] != null)
                //{
                //    response.DiagnosisList = ListsDataSet.Tables[2];
                //}
                if (ListsDataSet.Tables[2] != null)
                {
                    response.StateList = ListsDataSet.Tables[2];
                }
                if (ListsDataSet.Tables[3] != null)
                {
                    response.ReferringPhysicians = ListsDataSet.Tables[3];
                }

            }
            return response;
        }
    }
}
